/*
 * UploadCarrier.cpp
 *
 *  Created on: 2013年8月22日
 *      Author: sun
 */

#include "TrackerCarrier.h"
#include "SDFSRequest.h"
#include "SDFSResponse.h"
#include "FileHelper.h"
#include "common_define.h"
#include "tracker_global.h"
#include "TrackerConnectionPool.h"
#include "Log.h"


namespace sdfs {

TrackerCarrier::TrackerCarrier()
{
	m_ver = 0x01;
	m_method = _upload_;
}

TrackerCarrier::~TrackerCarrier()
{
}

bool TrackerCarrier::isTasktype(void *head)
{
	RequsetHeader *pHead = (RequsetHeader *)head;
	return pHead->ver == m_ver && pHead->method == m_method;
}
/**
 * handle clients' upload request
 * 1. find save storages
 * 2. read stream, dispatch file into storages
 */
void *TrackerCarrier::Upload(Request *req, Response *resp)
{
	SDFSRequest *clirequset = (SDFSRequest *)req;
	SDFSResponse *cliresponse = (SDFSResponse *)resp;
	context_len_t len = clirequset->GetContextLength();

	TrackerConnectionPool* connections = TrackerConnectionPool::GetInstance();
	Socket *socket = connections->GetConnection("storage01");
	SDFSRequest uploadRequest(socket);
	uploadRequest.

	context_len_t nRead = 0;

	char buf[8192];
	int size;
	Log::Debug("start accpeting data...");

	while(nRead < len)
	{
		size = clirequset->ReadContext(buf, 8192);
		socket->Write(buf, size);
	}


	//for
		//read from socket

		//write to stoarge server

	//return

}

} /* namespace sdfs */           
